# coding:utf-8
from gevent import monkey; monkey.patch_all()
import gevent
from urllib.request import urlopen
from gevent import monkey

monkey.patch_all()  # 把当前程序的所有的IO操作给我单独的做上标记

def f(url):
    print('GET: %s' % url)
    resp = urlopen(url)
    data = resp.read()
    f = open('url.html','wb')
    f.write(data)
    f.close()
    print('%d bytes received from %s. ' % (len(data), url))


def main():
    gevent.joinall([
        gevent.spawn(f, 'https://www.python.org/'),
        gevent.spawn(f, 'https://www.yahoo.com/'),
        gevent.spawn(f, 'https://github.com/')
    ])
    pass


if __name__ == '__main__':
    import time
    time_start = time.time()
    main()
    print(time.time()-time_start)